
# Replication code for Acquarone, Iris. E and Di Landro, Gonzalo (2024)
# "Historically Marginalized Groups and Ideological Representation in Legislatures"
# Legislative Studies Quarterly

library(tidyverse)
library(ggplot2)
library(ggpubr)
library(stargazer)

load("mp_dataset.RData")
load("party_dataset.RData")

# Main paper Figure 1 ----------------------------------------------------------------
# Ideological Self-Placement of Legislators From HMGs in Latin America (1998-2019)

# Women more leftist?

# m1: Country FE
m1_woman <- lm(lrself ~ woman + country, 
               data = mp_dataset, weights = PELA_wght)

# m2: Country FE; Year FE
m2_woman <- lm(lrself ~ woman + country + year, 
               data = mp_dataset, weights = PELA_wght)

# m3: Country and Legislature FE
m3_woman <- lm(lrself ~ woman + country + legislature, 
               data = mp_dataset, weights = PELA_wght)

# m4: Party FE
m4_woman <- lm(lrself ~ woman + partyfacts_id, 
               data = mp_dataset, weights = PELA_wght)

# m5: Party FE; Year FE
m5_woman <- lm(lrself ~ woman + year + partyfacts_id, 
               data = mp_dataset, weights = PELA_wght)

# m6: Party FE; Legislature FE
m6_woman <- lm(lrself ~ woman + legislature + partyfacts_id, 
               data = mp_dataset, weights = PELA_wght)

reg_output1 <- data.frame(
  group = rep("Women", 6),
  model_name = c("m1_woman", "m2_woman", "m3_woman", "m4_woman", "m5_woman", "m6_woman"),
  model_lab = c("Country FEs", "Country and Year FEs", "Country and Legislature FEs", "Party FEs", "Party and Year FEs", "Party and Legislature FEs"),
  estimated_coeff = sapply(list(m1_woman, m2_woman, m3_woman, m4_woman, m5_woman, m6_woman), function(x) coef(x)["woman"]),
  lower = sapply(list(m1_woman, m2_woman, m3_woman, m4_woman, m5_woman, m6_woman), function(x) confint(x)["woman", 1]),
  upper = sapply(list(m1_woman, m2_woman, m3_woman, m4_woman, m5_woman, m6_woman), function(x) confint(x)["woman", 2])
)

# Non-white more leftist?

# m1: Country FE
m1_nw <- lm(lrself ~ non_white + country, 
                  data = mp_dataset, weights = PELA_wght)

# m2: Country FE; Year FE
m2_nw <- lm(lrself ~ non_white + country + year, 
                  data = mp_dataset, weights = PELA_wght)

# m3: Country and Legislature FE
m3_nw <- lm(lrself ~ non_white + country + legislature, 
                  data = mp_dataset, weights = PELA_wght)

# m4: Party FE
m4_nw <- lm(lrself ~ non_white + partyfacts_id, 
                  data = mp_dataset, weights = PELA_wght)

# m5: Party FE; Year FE
m5_nw <- lm(lrself ~ non_white + year + partyfacts_id, 
                  data = mp_dataset, weights = PELA_wght)

# m6: Party FE; Legislature FE
m6_nw <- lm(lrself ~ non_white + legislature + partyfacts_id, 
                  data = mp_dataset, weights = PELA_wght)



reg_output2 <- data.frame(
  group = rep("Non-Whites", 6),
  model_name = c("m1_nw", "m2_nw", "m3_nw", "m4_nw", "m5_nw", "m6_nw"),
  model_lab = c("Country FEs", "Country and Year FEs", "Country and Legislature FEs", "Party FEs", "Party and Year FEs", "Party and Legislature FEs"),
  estimated_coeff = sapply(list(m1_nw, m2_nw, m3_nw, m4_nw, m5_nw, m6_nw), function(x) coef(x)["non_white"]),
  lower = sapply(list(m1_nw, m2_nw, m3_nw, m4_nw, m5_nw, m6_nw), function(x) confint(x)["non_white", 1]),
  upper = sapply(list(m1_nw, m2_nw, m3_nw, m4_nw, m5_nw, m6_nw), function(x) confint(x)["non_white", 2])
)

# Young more leftist?

# m1: Country FE
m1_young <- lm(lrself ~ young_adult + country, 
               data = mp_dataset, weights = PELA_wght)

# m2: Country FE; Year FE
m2_young <- lm(lrself ~ young_adult + country + year, 
               data = mp_dataset, weights = PELA_wght)

# m3: Country and Legislature FE
m3_young <- lm(lrself ~ young_adult + country + legislature, 
               data = mp_dataset, weights = PELA_wght)

# m4: Party FEs
m4_young <- lm(lrself ~ young_adult + partyfacts_id, 
               data = mp_dataset, weights = PELA_wght)

# m5: Party FE; Year FE
m5_young <- lm(lrself ~ young_adult + year + partyfacts_id, 
               data = mp_dataset, weights = PELA_wght)

# m6: Legislature FE; Party FE
m6_young <- lm(lrself ~ young_adult + legislature + partyfacts_id, 
               data = mp_dataset, weights = PELA_wght)



reg_output3 <- data.frame(
  group = rep("Young Adults", 6),
  model_name = c("m1_young", "m2_young", "m3_young", "m4_young", "m5_young", "m6_young"),
  model_lab = c("Country FEs", "Country and Year FEs", "Country and Legislature FEs", "Party FEs", "Party and Year FEs", "Party and Legislature FEs"),
  estimated_coeff = sapply(list(m1_young, m2_young, m3_young, m4_young, m5_young, m6_young), function(x) coef(x)["young_adult"]),
  lower = sapply(list(m1_young, m2_young, m3_young, m4_young, m5_young, m6_young), function(x) confint(x)["young_adult", 1]),
  upper = sapply(list(m1_young, m2_young, m3_young, m4_young, m5_young, m6_young), function(x) confint(x)["young_adult", 2])
)

reg_output <- rbind(reg_output1, reg_output2, reg_output3)

reg_output$group <- factor(reg_output$group, levels = c("Women", "Non-Whites", "Young Adults"))

reg_output$model_lab <- factor(reg_output$model_lab,
                               levels = c("Party and Legislature FEs",
                                          "Party and Year FEs",
                                          "Party FEs",
                                          "Country and Legislature FEs",
                                          "Country and Year FEs",
                                          "Country FEs"))

ggplot(reg_output, aes(x = estimated_coeff, y = model_lab)) +
  geom_point() +
  geom_errorbar(aes(xmin = lower, xmax = upper), width = 0.1) +
  geom_vline(xintercept = 0, linetype = "dashed") +
  facet_grid(~ group) +
  labs(title = "",
       x = "Estimated coefficient for each sociodemographic background",
       y = "Model") +
  theme_bw() +
  xlim(c(-1.1, 1.1))



# Main paper Table 1 ----------------------------------------------------------------
# Presence of Legislators From HMGs and Party Ideology

# Aggregate women
aw1 <- lm(pty_econ_lr_led ~ percentage_women  + country + year, 
          data = party_dataset)

aw2 <- lm(pty_econ_lr_led ~ percentage_women  + support_from_womeng + 
            inclusiveness_cselection + seatshare + country + year, 
          data = party_dataset)

aw3 <- lm(pty_econ_lr_led ~ percentage_women  + country + year + partyfacts_id, 
          data = party_dataset)

# Aggregate non-white
an1 <- lm(pty_econ_lr_led ~ percentage_nonwhite  + country + year, 
          data = party_dataset)

an2 <- lm(pty_econ_lr_led ~ percentage_nonwhite  + support_from_ethnicg + 
            inclusiveness_cselection + seatshare + country + year, 
          data = party_dataset)

an3 <- lm(pty_econ_lr_led ~ percentage_nonwhite  + country + year + partyfacts_id, 
          data = party_dataset)

# Aggregate young
ay1 <- lm(pty_econ_lr_led ~ percentage_youngadult  + country + year, 
          data = party_dataset)

ay2 <- lm(pty_econ_lr_led ~ percentage_youngadult  + inclusiveness_cselection + 
            seatshare + country + year, 
          data = party_dataset)

ay3 <- lm(pty_econ_lr_led ~ percentage_youngadult  + country + year + partyfacts_id, 
          data = party_dataset)

variable_order <- c("percentage_women", "percentage_nonwhite", "percentage_youngadult",
                    "support_from_womeng", "support_from_ethnicg",
                    "inclusiveness_cselection", "seatshare")

variable_labels <- c("Women", "Non-white", "Young adults")

stargazer(aw1, aw2, aw3, an1, an2, an3, ay1, ay2, ay3,
          type = "text",
          omit = c("country", "year", "partyfacts_id", "support_from_womeng",
                   "support_from_ethnicg","seatshare","inclusiveness_cselection"), 
          omit.stat = c("f", "ser"),
          star.cutoffs = c(0.05, 0.01, 0.001),
          order = variable_order,  
          covariate.labels = variable_labels,  
          add.lines = list(
            c("Country FE", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes"),
            c("Year FE", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes"),
            c("Party FE", "No", "No", "Yes", "No", "No", "Yes", "No", "No", "Yes")
          ))

# Appendix Figure 1 ----------------------------------------------------------------
# Descriptive statistics of MPs

# Ideology 
mp_dataset$lrself_toplot <- factor(mp_dataset$lrself, 
                                             levels = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, NA),
                                             ordered = TRUE)

lr <- ggplot(mp_dataset, aes(x = lrself_toplot, weight = PELA_wght)) +
  geom_bar(fill = "black") +
  theme_bw() +
  labs(title = "Ideology",
       x = "",
       y = "Count") +
  scale_x_discrete(labels = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Missing"))

# Gender
gender <- ggplot(mp_dataset, aes(x = as.character(woman), weight = PELA_wght)) +
  geom_bar(fill = "black") +
  theme_bw() +
  labs(title = "Gender",
       x = "",
       y = "Count") +
  scale_x_discrete(labels = c("Men", "Women", "Missing"))

# Age
age1 <- ggplot(mp_dataset, aes(x = as.numeric(as.character(age)), weight = PELA_wght)) +
  geom_histogram(fill = "black") +
  theme_bw() +
  labs(title = "Age (a)",
       x = "",
       y = "Count")

age2 <- ggplot(mp_dataset, aes(x = as.character(young_adult), weight = PELA_wght)) +
  geom_bar(fill = "black") +
  theme_bw() +
  labs(title = "Age (b)",
       x = "",
       y = "Count") +
  scale_x_discrete(labels = c("Not Young Adults", "Young Adults", "Missing"))

# Ethnicity
eth1 <- ggplot(mp_dataset, aes(x = ethnicity, weight = PELA_wght)) +
  geom_bar(fill = "black") +
  theme_bw() +
  labs(title = "Ethnicity (a)",
       x = "",
       y = "Count") +
  scale_x_discrete(labels = c("Asian", "White", "Indigenous", "Mestiza", "Mulata", "Black", "Other", "Missing")) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

eth2 <- ggplot(mp_dataset, aes(x = as.character(non_white), weight = PELA_wght)) +
  geom_bar(fill = "black") +
  theme_bw() +
  labs(title = "Ethnicity (b)",
       x = "",
       y = "Count") +
  scale_x_discrete(labels = c("Not-White", "White", "Missing")) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

ggarrange(lr, gender,
          age1, age2,
          eth1, eth2,
          ncol = 2, nrow = 3)


# Appendix Figure 2 ----------------------------------------------------------------
# Descriptive statistics of parties 

# Ideology

plr <- ggplot(party_dataset, aes(x = pty_econ_lr)) +
  geom_density() +
  theme_bw() +
  labs(title = "Party ideology",
       x = "",
       y = "Density")

# Support groups
s1 <- ggplot(party_dataset, aes(x = support_from_ethnicg)) +
  geom_density() +
  theme_bw() +
  labs(title = "Support: ethnic groups",
       x = "",
       y = "Density")

s2 <- ggplot(party_dataset, aes(x = support_from_womeng)) +
  geom_density() +
  theme_bw() +
  labs(title = "Support: women's groups",
       x = "",
       y = "Density")

# Inclusiveness of candidate selection
inc <- ggplot(party_dataset, aes(x = inclusiveness_cselection)) +
  geom_density() +
  theme_bw() +
  labs(title = "Inclusiveness of c. selection",
       x = "",
       y = "Density")

# Seat share
seat <- ggplot(party_dataset, aes(x = seatshare)) +
  geom_density() +
  theme_bw() +
  labs(title = "Seat share",
       x = "",
       y = "Density")

ggarrange(plr,
          s1, s2,
          inc, seat,
          ncol = 2, nrow = 3)


# Appendix Table 2 ----------------------------------------------------------------
# Gender and Ideology
stargazer(m1_woman, m2_woman, m3_woman, m4_woman, m5_woman, m6_woman,
          type = "text",
          omit = c("country", "year", "partyfacts_id", "legislature"), 
          star.cutoffs = c(0.05, 0.01, 0.001),
          omit.stat = c("f", "ser"),
          add.lines = list(
            c("Country FE", "Yes", "Yes", "Yes", "No", "No", "No"),
            c("Year FE", "No", "Yes", "No", "No", "Yes", "No"),
            c("Legislature FE", "No", "No", "Yes", "No", "No", "Yes"),
            c("Party FE", "No", "No", "No", "Yes", "Yes", "Yes")
          ))
# Appendix Table 3 ----------------------------------------------------------------
# Race/Ethnicity and Ideology
stargazer(m1_nw, m2_nw, m3_nw, m4_nw, m5_nw, m6_nw,
          type = "text",
          omit = c("country", "year", "partyfacts_id", "legislature"), 
          star.cutoffs = c(0.05, 0.01, 0.001),
          omit.stat = c("f", "ser"),
          add.lines = list(
            c("Country FE", "Yes", "Yes", "Yes", "No", "No", "No"),
            c("Year FE", "No", "Yes", "No", "No", "Yes", "No"),
            c("Legislature FE", "No", "No", "Yes", "No", "No", "Yes"),
            c("Party FE", "No", "No", "No", "Yes", "Yes", "Yes")
          ))



# Appendix Table 4 ----------------------------------------------------------------
# Age and Ideology
stargazer(m1_young, m2_young, m3_young, m4_young, m5_young, m6_young,
          type = "text",
          omit = c("country", "year", "partyfacts_id", "legislature"), 
          star.cutoffs = c(0.05, 0.01, 0.001),
          omit.stat = c("f", "ser"),
          add.lines = list(
            c("Country FE", "Yes", "Yes", "Yes", "No", "No", "No"),
            c("Year FE", "No", "Yes", "No", "No", "Yes", "No"),
            c("Legislature FE", "No", "No", "Yes", "No", "No", "Yes"),
            c("Party FE", "No", "No", "No", "Yes", "Yes", "Yes")
          ))
# Appendix Table 5 ----------------------------------------------------------------
# Presence of Legislators From HMGs and Party Ideology (full model)
stargazer(aw1, aw2, aw3, an1, an2, an3, ay1, ay2, ay3,
          type = "text",
          omit = c("country", "year", "partyfacts_id"), 
          omit.stat = c("f", "ser"),
          star.cutoffs = c(0.05, 0.01, 0.001),
          order = variable_order,  
          covariate.labels = variable_labels,  
          add.lines = list(
            c("Country FE", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes"),
            c("Year FE", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes"),
            c("Party FE", "No", "No", "Yes", "No", "No", "Yes", "No", "No", "Yes")
          ))
# Appendix Table 6 ----------------------------------------------------------------
# Ideology of Legislators Under 40 vs. 40 and Older

# m1: Country FE
m1_y40 <- lm(lrself ~ young_adult40 + country, 
                 data = mp_dataset, weights = PELA_wght)

# m2: Country FE; Year FE
m2_y40 <- lm(lrself ~ young_adult40 + country + year, 
                 data = mp_dataset, weights = PELA_wght)

# m3: Country and Legislature FE
m3_y40 <- lm(lrself ~ young_adult40 + country + legislature, 
                 data = mp_dataset, weights = PELA_wght)

# m4: Party FEs
m4_y40 <- lm(lrself ~ young_adult40 + partyfacts_id, 
               data = mp_dataset, weights = PELA_wght)

# m5: Party FE; Year FE
m5_y40 <- lm(lrself ~ young_adult40 + year + partyfacts_id, 
                 data = mp_dataset, weights = PELA_wght)

# m6: Legislature FE; Party FE
m6_y40 <- lm(lrself ~ young_adult40 + legislature + partyfacts_id, 
                 data = mp_dataset, weights = PELA_wght)

stargazer(m1_y40, m2_y40, m3_y40, m4_y40, m5_y40, m6_y40,
          type = "text",
          omit = c("country", "year", "partyfacts_id", "legislature"), 
          star.cutoffs = c(0.05, 0.01, 0.001),
          omit.stat = c("f", "ser"),
          add.lines = list(
            c("Country FE",    "Yes", "Yes", "Yes", "No", "No","No"),
            c("Year FE",        "No", "Yes", "No", "No", "Yes","No"),
            c("Legislature FE", "No", "No", "Yes", "No", "No","Yes"),
            c("Party FE",       "No", "No", "No", "Yes", "Yes","Yes")
          ))


# Appendix Table 7 ----------------------------------------------------------------
# Presence of Legislators From HMGs and Party Ideology Using CMP

# Aggregate women
aw1 <- lm(rile_led ~ percentage_women + country + year, data = party_dataset)

aw2 <- lm(rile_led ~ percentage_women + support_from_womeng + inclusiveness_cselection + seatshare + country + year, data = party_dataset)

aw3 <- lm(rile_led ~ percentage_women + country + year + partyfacts_id, data = party_dataset)

# Aggregate notwhite
an1 <- lm(rile_led ~ percentage_nonwhite + country + year, data = party_dataset)

an2 <- lm(rile_led ~ percentage_nonwhite + support_from_ethnicg + inclusiveness_cselection + seatshare + country + year, data = party_dataset)

an3 <- lm(rile_led ~ percentage_nonwhite + country + year + partyfacts_id, data = party_dataset)

# Aggregate young
ay1 <- lm(rile_led ~ percentage_youngadult + country + year, data = party_dataset)

ay2 <- lm(rile_led ~ percentage_youngadult + inclusiveness_cselection + seatshare + country + year, data = party_dataset)

ay3 <- lm(rile_led ~ percentage_youngadult + country + year + partyfacts_id, data = party_dataset)

variable_order <- c("percentage_women", "percentage_nonwhite", "percentage_youngadult",
                    "support_from_womeng", "support_from_ethnicg",
                    "inclusiveness_cselection", "seatshare")

variable_labels <- c("Women", "Non-white", "Young adults",
                     "Support: women", "Support: ethnic",
                     "Inclusiveness", "Seat Share")

stargazer(aw1, aw2, aw3, an1, an2, an3, ay1, ay2, ay3,
          type = "text",
          omit = c("country", "year", "partyfacts_id"), 
          omit.stat = c("f", "ser"),
          star.cutoffs = c(0.05, 0.01, 0.001),
          order = variable_order,  
          covariate.labels = variable_labels,  
          add.lines = list(
            c("Country FE", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes"),
            c("Year FE", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes"),
            c("Party FE", "No", "No", "Yes", "No", "No", "Yes", "No", "No", "Yes")))


# Appendix Table 8 ----------------------------------------------------------------
# Presence of Legislators From HMGs and Party Ideology Using Mean Party Placement by MPs From PELA

# Aggregate women
aw1 <- lm(mean_partyplacement_led ~ percentage_women + country + year, data = party_dataset)

aw2 <- lm(mean_partyplacement_led ~ percentage_women + support_from_womeng + inclusiveness_cselection + seatshare + country + year, data = party_dataset)

aw3 <- lm(mean_partyplacement_led ~ percentage_women + country + year + partyfacts_id, data = party_dataset)

# Aggregate notwhite
an1 <- lm(mean_partyplacement_led ~ percentage_nonwhite + country + year, data = party_dataset)

an2 <- lm(mean_partyplacement_led ~ percentage_nonwhite + support_from_ethnicg + inclusiveness_cselection + seatshare + country + year, data = party_dataset)

an3 <- lm(mean_partyplacement_led ~ percentage_nonwhite + country + year + partyfacts_id, data = party_dataset)

# Aggregate young
ay1 <- lm(mean_partyplacement_led ~ percentage_youngadult + country + year, data = party_dataset)

ay2 <- lm(mean_partyplacement_led ~ percentage_youngadult + inclusiveness_cselection + seatshare + country + year, data = party_dataset)

ay3 <- lm(mean_partyplacement_led ~ percentage_youngadult + country + year + partyfacts_id, data = party_dataset)

variable_order <- c("percentage_women", "percentage_nonwhite", "percentage_youngadult",
                    "support_from_womeng", "support_from_ethnicg",
                    "inclusiveness_cselection", "seatshare")

variable_labels <- c("Women", "Non-white", "Young adults",
                     "Support: women", "Support: ethnic",
                     "Inclusiveness", "Seat Share")

stargazer(aw1, aw2, aw3, an1, an2, an3, ay1, ay2, ay3,
          type = "text",
          omit = c("country", "year", "partyfacts_id"), 
          omit.stat = c("f", "ser"),
          star.cutoffs = c(0.05, 0.01, 0.001),
          order = variable_order,  
          covariate.labels = variable_labels,  
          add.lines = list(
            c("Country FE", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes"),
            c("Year FE", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes"),
            c("Party FE", "No", "No", "Yes", "No", "No", "Yes", "No", "No", "Yes")))


# Appendix Table 9 ----------------------------------------------------------------
# Presence of Legislators From HMGs and Party Ideology Controlling for Gender Quota Implementation

# Aggregate women
aw1 <- lm(pty_econ_lr_led ~ percentage_women + country + year + implemented.quota, 
          data = party_dataset)

aw2 <- lm(pty_econ_lr_led ~ percentage_women + support_from_womeng + inclusiveness_cselection + 
            seatshare + country + year + implemented.quota, 
          data = party_dataset)

aw3 <- lm(pty_econ_lr_led ~ percentage_women + country + year + partyfacts_id + 
            implemented.quota, 
          data = party_dataset)

# Aggregate notwhite
an1 <- lm(pty_econ_lr_led ~ percentage_nonwhite + country + year, 
          data = party_dataset)

an2 <- lm(pty_econ_lr_led ~ percentage_nonwhite + support_from_ethnicg + inclusiveness_cselection + 
            seatshare + country + year, 
          data = party_dataset)

an3 <- lm(pty_econ_lr_led ~ percentage_nonwhite + country + year + partyfacts_id, 
          data = party_dataset)

# Aggregate young
ay1 <- lm(pty_econ_lr_led ~ percentage_youngadult + country + year + implemented.quota, 
          data = party_dataset)

ay2 <- lm(pty_econ_lr_led ~ percentage_youngadult + inclusiveness_cselection + seatshare + 
            country + year + implemented.quota, 
          data = party_dataset)

ay3 <- lm(pty_econ_lr_led ~ percentage_youngadult + country + year + partyfacts_id + 
            implemented.quota, 
          data = party_dataset)

variable_order <- c("percentage_women", "percentage_nonwhite", "percentage_youngadult",
                    "support_from_womeng", "support_from_ethnicg",
                    "inclusiveness_cselection", "seatshare", "implemented.quota")

variable_labels <- c("Women", "Non-white", "Young adults",
                     "Support: women", "Support: ethnic",
                     "Inclusiveness", "Seat share", "Implemented quota")

stargazer(aw1, aw2, aw3, an1, an2, an3, ay1, ay2, ay3,
          type = "text",
          omit = c("country", "year", "partyfacts_id"), 
          omit.stat = c("f", "ser"),
          star.cutoffs = c(0.05, 0.01, 0.001),
          order = variable_order,  
          covariate.labels = variable_labels,  
          add.lines = list(
            c("Country FE", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes"),
            c("Year FE", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes"),
            c("Party FE", "No", "No", "Yes", "No", "No", "Yes", "No", "No", "Yes")
          ))

# Appendix Table 10 ----------------------------------------------------------------
# Party Ideology and Selection
  
left1 <- glm(woman ~ pty_econ_lr + country + legislature,
             data = mp_dataset, family = "binomial", weights = PELA_wght)

left2 <- glm(non_white ~ pty_econ_lr + country + legislature,
             data = mp_dataset, family = "binomial", weights = PELA_wght)

left3 <- glm(young_adult ~ pty_econ_lr + country + legislature,
             data = mp_dataset, family = "binomial", weights = PELA_wght)

variable_order <- c("woman", "non_white", "young_adult")

stargazer(left1, left2, left3,
          type = "text",
          omit = c("country", "year", "legislature"),
          omit.stat = c("f", "ser"),
          star.cutoffs = c(0.05, 0.01, 0.001),
          order = variable_order,
          add.lines = list(
            c("Country FE", "Yes", "Yes", "Yes"),
            c("Legislature FE", "Yes", "Yes", "Yes")))

